package com.zhuozhengsoft.pageoffice6springboot2back.controller;

import com.zhuozhengsoft.pageoffice.*;
import com.zhuozhengsoft.pageoffice6springboot2back.util.GetDirPathUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@RestController
@RequestMapping(value = "/FileMakerPrintFiles/")
public class FileMakerPrintFilesController {
    //获取doc目录的磁盘路径
    private final String dir = GetDirPathUtil.getDirPath() + "static/doc/";

    public FileMakerPrintFilesController() throws IOException {
    }

    @RequestMapping(value = "/filemaker")
    public void filemakerWord(HttpServletRequest request, HttpServletResponse response, int id) throws IOException {
        String fileName = "doc_" + id + ".doc";
        FileMakerCtrl fmCtrl = new FileMakerCtrl(request);
        fmCtrl.fillDocument("/doc/FileMakerPrintFiles/" + fileName, DocumentOpenType.Word);
        response.getOutputStream().print(fmCtrl.getHtml());
    }

    @RequestMapping(value = "/preview")
    public String preview(HttpServletRequest request,int id)  {
        String fileName = "doc_" + id + ".doc";
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.webOpen("/doc/FileMakerPrintFiles/" + fileName, OpenModeType.docReadOnly, "张三");
        return poCtrl.getHtml();
    }

}
